<?php

declare(strict_types=1);

namespace app\validate;

use think\Validate;

/**
 * 用户注册验证器
 * 
 * @link https://doc.thinkphp.cn/v8_0/validator.html
 */
class SignupValidate extends Validate
{
    /**
     * 定义验证规则
     * @var array
     */
    protected $rule = [
        'username' => 'require|length:3,40|chsDash|unique:users',
        'email'    => 'require|email|unique:users',
        'password' => 'require|length:6,20',
        'captcha'  => 'require|captcha',
    ];

    /**
     * 定义错误信息
     * @var array
     */
    protected $message = [
        'username.require' => '请输入用户名',
        'username.length'  => '用户名长度为 3-40 个字符',
        'username.chsDash' => '用户名只能包含汉字、字母、数字、下划线和破折号',
        'username.unique'  => '用户名已存在',
        'email.require'    => '请输入邮箱',
        'email.email'      => '邮箱格式不正确',
        'email.unique'     => '邮箱已被注册',
        'password.require' => '请输入密码',
        'password.length'  => '密码长度为 6-20 个字符',
        'captcha.require'  => '请填写验证码',
        'captcha.captcha'  => '验证码错误',
    ];
}
